<template>
	<view class="container">
		<view class="header"></view>
		<view class="pic">
			<image v-if="info.realPic" :src="imgUrl+info.realPic"></image>
			<image v-else :src="info.avatar"></image>
			<view>{{info.realname}}</view>
			<view>{{info.sex}}/{{info.age}}岁/{{info.workTime}}/{{info.education}}</view>
		</view>
		<view class="order" style="margin-top:140rpx;">
			<view class="title">
			简历信息
		  </view>
			<view class="list">
				<view class="item">意向职位:<text class="itemInfo">{{info.post}}</text></view>
				<view class="item">出生日期:<text class="itemInfo"> {{info.birthDay}}</text></view>
				<view class="item">学历: <text class="itemInfo">{{info.education}}</text></view>
				<view class="item">工作经验:<text class="itemInfo"> {{info.workTime}}</text></view>
				<view class="item">目前状态: <text class="itemInfo">{{info.workType}}</text></view>
				<view class="item">期望薪资: <text class="itemInfo">{{info.money}}</text></view>
				<view class="item">期望工作地点:<text class="itemInfo"> {{info.city}}</text></view>
				<view class="item">职业培训: <text class="itemInfo">{{info.business}}</text></view>
			</view>
		</view>
		<view class="order">
			<view class="title">
			  联系方式
		  </view>
			<view class="list" v-if ="showcontact">
				<view @click ="doCall(info.phone)" class="item">联系电话 :{{info.phone}}</view>
			</view>
			<view class="list" v-else>
				<button v-if="requestShow && role == 3" @click="getSeeType('toSelectlook')">查看联系方式</button>
				<button style="background:#b3b3b3" v-else disabled>查看联系方式</button>
			</view>
		</view>
		<view class="order">
			<view class="title">
			 工作经历:
		  </view>
			<view class="content">
				<view>{{info.workList}}</view>
			</view>
		</view>
		<view class="order">
			<view class="title">
			 个人特长:
		  </view>
			<view class="content">
				<view>{{info.advantage}}</view>
			</view>
		</view>
		<view class="footer" v-if="role == 3">
		    <view class="fsctrue" v-if="!collecttrue" @click="collectRresume">
		       收藏简历 
		    </view>
		    <view class="fscfalse" v-if="collecttrue">
		       收藏简历 
		    </view>
		    <view class="online" @click="getVip('online')">
		        立即沟通
		    </view>
		    <view class="fyqfalse" v-if="interviewShow">
		        面试邀请
		    </view>
		    <view class="fyqtrue" v-else @click="getVip('interview')">
		        面试邀请
		    </view>
		</view>
		
		<view class="weixinmao-msg-userinfo" v-if="sendTimeShow">
		    <view class="weixinmao-content-userinfo">
		        <view class="userinfo-title">
		             选择面试时间:
		        </view>
		        <view class="section1">
		            <view class="section__title">选择日期:</view>
					<picker mode="date" :value="date" start="2020-11-01" @change="bindDateChange" data-name="date">
					    <view class="uni-input">{{date}}</view>
					</picker>
		        </view>
		        <view class="section1">
		            <view class="section__title">选择时间:</view>
		            <picker mode="time" :value="time" @change="bindDateChange" data-name="time">
		                <view class="picker">
		                    {{time}}
		                </view>
		            </picker>
		        </view>
		        <view class="userinfo-button">
		            <button @click="submit">确定</button>
		            <button @click="fail()">取消</button>
		        </view>
		    </view>
		</view>
		<view @click="jumpVip" v-if="role == 3" class="frame">VIP</view>
	</view>
</template>
<script>
import request from '@/util/request.js'	
export default {
	data() {
		return {
			role:0,
			imgUrl:this.url,
			info:[],
			showcontact:false,
			requestShow:true,
			collecttrue:false,
			interviewShow:false,
			vipType:false,
			vipId:0,
			sendTimeShow:false,
			time:'09:00',
			date:'2021-02-01',
			seeNum:0
		}
	},
	onLoad:function(e){
		this.role = uni.getStorageSync('role')
		uni.showLoading({
		    title: '加载中'  
		});
		this.getInfo(e.uid)
		this.getVipType(e.uid)
	},
	methods: {
		getInfo:function(uid){
			var data = {'uid':uid}
			var that = this
			request({
				url: 'memberInfo/info',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					that.info = res.data.data
					//是否收藏此简历
					that.getcollect(res.data.data.id);
				}
			})
		},
		getVipType:function(uid){
			var data = {
				'uid':uni.getStorageSync('uid')
			}
			var that = this
			request({
				url: 'vip/lable',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						console.log(res.data.data.count)
						that.vipType = true,
						that.vipId = res.data.data.id
						that.seeNum = res.data.data.count
						//当前机构是vip会员时,在查询 是否给当前人才 发送过简历
						//是否查询过 当前人才的手机号码
						that.getSee(uid);
						that.getinterview(uid);
					}
				}
			})
		},
		getcollect:function(id){
			var data = {
				'uid':uni.getStorageSync('uid'),
				'rid':id,
				'type':3
			}
			var that = this
			request({
				url: 'collection/info',
				method: 'get',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						that.collecttrue = true
					}
				}
			})
		},
		getSee:function(uid){
			var that = this;
			var data = {
				'company_uid':uni.getStorageSync('uid'),
				'uid':uid,
			}
			request({
				url: 'phoneSee/is_see',
				method: 'get',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						if(res.data.data.type == 2){
							that.showcontact = true
						}else{
							that.showcontact = false
							that.requestShow = false
						}
					}else{
						that.showcontact = false
						that.requestShow = true
					}
				}
			})
		},
		getSeeType:function(key){
			var that = this
			console.log(this.seeNum)
			if(this.seeNum > 0){
				uni.showModal({
					title: '提示',
					content: '您是白金VIP会员,可以享受直接查看电话的权限,是否使用？',
					success: function (res) {
						if (res.confirm) {
							that.vipSee(key)
						} else if (res.cancel) {
							that.numDec(key);
						}
					}
				});
			}else{
				this.numDec(key);
			}
		},
		vipSee:function(key){
			var that = this
			var data = {
				'company_uid':uni.getStorageSync('uid'),
				'uid':this.info.uid,
				'vipId':this.vipId
			}
			console.log(data)
			request({
				url: 'vip/numDec',
				method: 'post',
				data:data,
				success: (res) => {
					console.log(res)
					if(res.data.code == 1){
						var arr = {
						    'company_uid':uni.getStorageSync('uid'),
						    'uid':that.info.uid
						}
						request({
							url: 'phoneSee/vipAdd',
							method: 'post',
							data:arr,
							success: (res) => {
								if(res.data.code == 1){
								    that.showcontact = true
								}
							},
						})
					}else{
						uni.showToast({
							title: '系统错误!!',
							icon: "none", 
							position:'bottom',
						});
					}
				},
			})
		},
		getinterview:function(uid){
			var data = {
				'company_uid':uni.getStorageSync('uid'),
				'uid':uid,
			}
			var that = this
			request({
				url: 'interview/is_inter',
				method: 'get',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						that.interviewShow = true
					}
				}
			})
		},
		collectRresume:function(){
			var that = this;
			var data = {
				'uid':uni.getStorageSync('uid'),
				'rid':this.info.id,
				'type':3
			}
			request({
				url: 'collection/add',
				method: 'POST',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						uni.showToast({
							title: '简历收藏成功!!',
							icon: "none", 
							position:'bottom',
						});
						that.collecttrue = true
					}
				}
			})
		},
		getVip:function(key){
			// uni.showToast({
			// 	title: '正在开发,请稍等!!',
			// 	icon: "none", 
			// 	position:'bottom',
			// });
			// return;
			
			if(this.vipType){
				//是vip客户可以发送邀请
				this.numDec(key);
			}else{
				uni.showToast({
					title:'未购买VIP套餐或VIP已过期!!',
					icon: 'none',
					duration: 2000,
					success() {
						setTimeout(function() {
							uni.navigateTo({
								url:'/pages/vip/index'
							});
						}, 2000);
					}
				})
			}
		},
		numDec:function(key){
			var that = this
			var data = {
				'company_uid':uni.getStorageSync('uid'),
				'uid':this.info.uid,
				'vipId':this.vipId,
			}
			request({
				url: 'vip/numDec',
				method: 'POST',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						that[key]()
					}else{
						uni.showToast({
							title: '系统错误!!',
							icon: "none", 
							position:'bottom',
						});
					}
				}
			})
		},
		online:function(){
			var id = this.info.uid
			uni.navigateTo({
				url:'/pages/message/online/toCompany?touid='+id
			});
		},
		toSelectlook:function(){
			var that = this
			var data = {
				'company_uid':uni.getStorageSync('uid'),
				'uid':this.info.uid,
			}
			request({
				url: 'phoneSee/add',
				method: 'POST',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						uni.showToast({
							title: '请求成功,待求职者同意之后即可查看!!',
							icon: "none", 
							position:'bottom',
						});
						that.showcontact = false
						that.requestShow = false
					}
				}
			})
		},
		interview:function(){
			this.sendTimeShow = true
		},
		fail:function(){
			this.sendTimeShow = false
		},
		bindDateChange:function(e){
			let name = e.currentTarget.dataset.name
			this[name] = e.detail.value
		},
		submit:function(){
			var that = this
			var data = {
				'company_uid':uni.getStorageSync('uid'),
				'uid':this.info.uid,
				'date':this.date,
				'time':this.time
			}
			request({
				url: 'interview/interViewAdd',
				method: 'POST',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						uni.showToast({
							title: '面试邀请发送成功!!',
							icon: "none", 
							position:'bottom',
						});
						that.interviewShow = true
						that.sendTimeShow = false
					}
				}
			})
		},
		jumpVip:function(){
			uni.navigateTo({
				url:'/pages/vip/index'
			});
		},
	}
}
</script>
<style scoped>
	@import url("./css/info.css");
</style>